<?php
/**
 * 补报权限模型
 * @author jianhui
 */
class supplementRoleModel extends MY_Model{
    var $validStoreIdsByTimeUnit = null;
    function supplementRoleModel(){
        parent::MY_Model();
        $this->table = 'SupplementRole';
    }
    /**
     * 包装数据
     * @param array $list
     * @return Ambigous <string, unknown>
     */
    function packing($list = array()){
        //时间单位配置
        $this->CI->load->model('timeUnitModel');
        $timeUnitList = $this->CI->timeUnitModel->getCacheData('timeUnitList');
        //基金类型
        $fundType = $this->config->item('fundType');
        //补报类别
        $typeList = array(1=>'普通补报',2=>'特殊补报');
        foreach ($list as $k => $v){
            //基金类型
            $v['fundTypeStr'] = isset($fundType[$v['fundType']]) ? $fundType[$v['fundType']] : '';
            //补报类型
            $v['typeStr'] = isset($typeList[$v['type']]) ? $typeList[$v['type']] : ''; 
            //时间单位
            $v['timeUnitStr'] = isset($timeUnitList[$v['year']][$v['timeUnit']]) ? $timeUnitList[$v['year']][$v['timeUnit']] : '';
            //开始结束时间
            $v['startTimeStr'] = date("Y-m-d H:i:s", $v['startTime']);
            $v['endTimeStr'] = date("Y-m-d H:i:s", $v['endTime']);
            $list[$k] = $v;
        }
        return $list;
    }
    /**
     * 获取有效的专营店ID集，并按时段分组
     * @return [type] [description]
     */
    function getValidStoreIdsByTimeUnit($fundType, $type, $year){
        if (is_null($this->validStoreIdsByTimeUnit)) {
            $nowTime = time();
            $list = $this->getList(array(
                'year'  => $year,
                'fundType'  =>  $fundType,
                'type' => $type,
                'startTime <'=>$nowTime,
                'endTime >'=>$nowTime,
                'isDel' => 0,
            ));
            $validStoreIdsByTimeUnit = array();
            foreach ($list as $k => $v) {
                isset($validStoreIdsByTimeUnit[(int)$v['timeUnit']]) || $validStoreIdsByTimeUnit[(int)$v['timeUnit']] = array();
                $validStoreIdsByTimeUnit[(int)$v['timeUnit']][] = (int)$v['storeId'];
            }
            $this->validStoreIdsByTimeUnit = $validStoreIdsByTimeUnit;
        }
        return $this->validStoreIdsByTimeUnit;
    }
}